﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using _619BJP.Models;
using System.Data.SqlClient;
using System.Data;
using Microsoft.ApplicationBlocks.Data;

namespace _619BJP.Database.admin
{
    public class articleuploadDB
    {
        private string connString = System.Configuration.ConfigurationManager.ConnectionStrings["619BJP.Data.ConnectionString"].ConnectionString;

        /// <summary>
        /// 上传百科
        /// </summary>
        /// <param name="articelModel"></param>
        /// <returns></returns>
        public int uploadArticle(ArticleModel articelModel)
        {
            int ArticleID;
            using (SqlConnection conn = new SqlConnection(connString))
            {
                string sql = "INSERT INTO [AR_Article]([title],[content],[category_id],[created_by],[created_time])VALUES(@title,@content,@category_id,@created_by,@created_time);Select @@IDENTITY";
                SqlParameter[] paramsToSql = new SqlParameter[10];
                paramsToSql[0] = new SqlParameter("@title", SqlDbType.NVarChar);
                paramsToSql[0].Value = articelModel.title;
                paramsToSql[1] = new SqlParameter("@content", SqlDbType.NVarChar);
                paramsToSql[1].Value = articelModel.content;
                paramsToSql[2] = new SqlParameter("@category_id", SqlDbType.NVarChar);
                paramsToSql[2].Value = articelModel.category_id;
                paramsToSql[4] = new SqlParameter("@created_by", SqlDbType.NVarChar);
                paramsToSql[4].Value = articelModel.created_by;
                paramsToSql[5] = new SqlParameter("@created_time", SqlDbType.DateTime);
                paramsToSql[5].Value = System.DateTime.Now;

                ArticleID = Convert.ToInt32(SqlHelper.ExecuteScalar(conn, CommandType.Text, sql, paramsToSql));

            }
            return ArticleID;
        }
    }
}
